//
//  XGTopicCellTopView.m
//  BSBuDeJie
//
//  Created by monkey on 2018/12/30.
//  Copyright © 2018 itcast. All rights reserved.
//

#import <Masonry/Masonry.h>

#import "UIImageView+Extension.h"

#import "XGTopicCellTopView.h"

#import "XGTopicModel.h"

@interface XGTopicCellTopView ()

/// 头像
@property (nonatomic,strong) UIImageView *iconImageView;
/// 昵称
@property (nonatomic,strong) UILabel *nameLabel;
/// 创建时间
@property (nonatomic,strong) UILabel *createTimeLabel;

@end

@implementation XGTopicCellTopView

#pragma mark - 解析模型

- (void)setTopicModel:(XGTopicModel *)topicModel
{
    _topicModel = topicModel;
    [self.iconImageView xg_setImageWithURLString:topicModel.profileImage placeHolder:kPlaceHolderImage];
    self.nameLabel.text = topicModel.name;
    self.createTimeLabel.text = topicModel.passtime;
}

#pragma mark - 构造方法

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    
    return self;
}

- (void)setUpUI
{
    // 添加子控件
    [self addSubview:self.iconImageView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.createTimeLabel];
    
    // 设置自动布局
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(kUserIconWidth, kUserIconWidth));
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(kMargin);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView);
        make.left.equalTo(self.iconImageView.mas_right).offset(kMargin);
    }];
    
    [self.createTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.iconImageView);
        make.left.equalTo(self.nameLabel);
    }];
}

#pragma mark - 懒加载

- (UIImageView *)iconImageView
{
    if (_iconImageView == nil) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.layer.cornerRadius = kUserIconWidth / 2;
        _iconImageView.layer.masksToBounds = YES;
    }
    
    return _iconImageView;
}

- (UILabel *)nameLabel
{
    if (_nameLabel == nil) {
        _nameLabel = [UILabel labelWithText:@"测试文本" textColor:[UIColor blackColor] font:15 textAlignment:NSTextAlignmentCenter];
    }
    
    return _nameLabel;
}

- (UILabel *)createTimeLabel
{
    if (_createTimeLabel == nil) {
        _createTimeLabel = [UILabel labelWithText:@"2018-12:21 16:38:25" textColor:[UIColor lightGrayColor] font:12 textAlignment:NSTextAlignmentCenter];
    }
    
    return _createTimeLabel;
}



@end
